#!/bin/sh
#
# $FreeBSD$
#

# PROVIDE: kcptube
# REQUIRE: LOGIN DAEMON
# KEYWORD: shutdown

# Add these lines to /etc/rc.conf.local or /etc/rc.conf to enable `kcptube':
#
# kcptube_enable (bool):          Set to "NO" by default.
#                                 Set it to "YES" to enable kcptube
# kcptube_config (path):          Set to "/usr/local/etc/kcptube/config.conf" by default
#                                 Set it to the kcptube server config

. /etc/rc.subr

name="kcptube"
rcvar="${name}_enable"

eval ": \${${name}_enable:=\"NO\"}"
eval ": \${${name}_config:=\"/usr/local/etc/${name}/config.conf\"}"

pidfile="/var/run/${name}.pid"
procname="/usr/local/bin/kcptube"
configfile="$(eval echo \${${name}_config})"

start_precmd="kcptube_startprecmd"
start_cmd=kcptube_start

kcptube_startprecmd()
{
	touch "${pidfile}"
}

kcptube_start()
{
	/usr/sbin/daemon -c -p ${pidfile} ${procname} ${configfile} > /dev/null 2>&1
}

load_rc_config "$name"
run_rc_command "$1"
